{extend name="base/common"}

{block name="style"}
<style>
    .shadow{width: 100%;height: 100%;position: absolute;left: 0;top: 0;background: rgba(0,0,0,0.4);z-index: 888888888888888;}
    .b,.c{cursor: pointer;}
</style>
{/block}

{block name="page-header"}
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>班型分配</h2>
        <ol class="breadcrumb">
            <li>
                <a href="{:Url('Type/three?id='.$id)}">班型学员</a>
            </li>
            <li class="active">
                <strong>学员列表</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2">
    </div>
</div>
{/block}

{block name="main"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5 style="color: green">* {$class}</h5>
                    <form method="get" action="">
                        <div class="col-sm-3">
                            <div class="input-group">
                                <input type="text" placeholder="输入学校或@姓名" class="input-sm form-control" name="name" value="{notempty name='Think.get.name'}{$Think.get.name}{/notempty}">
                                <input type="hidden"  name="id" value="{$id}">
                                <input type="hidden"  name="party" id="party" value="{$party}">
                            <span class="input-group-btn">
                                <button type="submit" class="btn btn-sm btn-primary">查询</button>
                            </span>
                            </div>
                        </div></form>
                    <div class="ibox-tools">
                        年级筛选&emsp;
                        <select name="party" onchange="changeParty()">
                            {volist name="years" id="yy"}
                            <option value="{$yy}" {eq name="$party" value="$yy"} selected {/eq}>{eq name="$yy" value="0"}全部{else/}{$yy}{/eq}</option>
                            {/volist}
                        </select>
                        &emsp;
                        <a data-toggle="modal" class="btn btn-sm btn-primary check">批量操作</a>
                        <a href="{:Url('Type/three?id='.$id)}" class="btn btn-white btn-sm"><i class="fa fa-reply"></i> 返回</a>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th><input class="i-checks check-all" type="checkbox"></th>
                                <th>姓名</th>
                                <th>VIP账号</th>
                                <th>所属学校</th>
                                <th>本班型状态</th>
                                <th>该生所在班型（全部）</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr >
                                <td data-id="{$vo.openid}"><input type="checkbox" class="i-checks" name="input[]"></td>
                                <td width="10%">{$vo.name}</td>
                                <td width="10%">{$vo.order_id}</td>
                                <td class="name" width="20%">{$vo.school_id|getSchool}</td>
                                <td width="10%">{$vo.openid|getBX=###,$id}</td>
                                <td width="50%">{$vo.openid|getBX=###}</td>
                            </tr>
                            {/volist}
                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="10">
                                    <div class="page">{$list->render()}</div>
                                </td>
                            </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<iframe id="iframe" src="" style="height: 80%;width: 392px;z-index: 99;position: absolute;top: 10%;border: 0;left: 32%;background: #fff;display: none;" scrolling="auto" seamless></iframe>
<div class="shadow" style="display: none"></div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="margin: 300px auto">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
            </div>
            <div class="modal-body" style="font-size: 18px;text-align: center">
                请选择如何分配学员？
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default refuse_btn" style="background: #f00;color: #fff;float: left">移除
                </button>
                <button type="button" class="btn btn-primary pass_btn">
                    添加
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
{/block}

{block name="script"}
<script src="__ADMIN__/js/plugins/iCheck/icheck.min.js"></script>
<script>
    var ids ="{$id}";
    highlight_subnav("{:Url('Type/index')}");
    $(document).ready(function(){
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
        $('.check-all').on('ifChecked', function(event){
            $('input').iCheck('check');
        });

        $('.check-all').on('ifUnchecked', function(event){
            $('input').iCheck('uncheck');
        });
    });
    $(".check").on("click",function(){
        var checkArr = [];
        $("td .icheckbox_square-green").each(function(){
            if($(this).hasClass("checked")&& $(this).hasClass("disabled")==false){
                checkArr.push($(this).parent().data("id")+'');
            }
        });
        if(checkArr.length===0){
            updateAlert("未选择操作列表",'error');
            return false;
        }
        $("#myModal").modal('show');
        // 移除
        $(".refuse_btn").on("click",function(){
            reviewAjax(checkArr,2);
        })
        // 添加
        $(".pass_btn").on("click",function(){
            reviewAjax(checkArr,1);
        })
    });
    var id="{$id}";
    var reviewAjax = function(arr,pass){
        $(".refuse_btn").attr("disabled", true);
        $(".pass_btn").attr("disabled", true);
        $.ajax({
            type:"post",
            url:"{:Url('Type/play')}",
            data:{
                id:id,
                users:arr,
                type:pass
            },
            beforeSend:function () {
                $(".shadow").show();
            },
            success:function(data){
                $(".shadow").hide();
                if(data.code == 1){
                    $("#myModal").modal('hide');
                    updateAlert("操作成功",'success');
                    setTimeout(function(){
                        window.location.reload();
                    },1000)
                }
            }
        });
    };
    function changeParty(){
        var party = $("select[name='party']").val();
        $("input[name='party']").val(party);
        var school_id = "{$id}";
        location.href = "{:Url('Type/two')}?id="+school_id+"&party="+party;
    }
</script>
{/block}